﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Nizm0.QOT.Library.Generators
{
    class Nip
    {
        private int[] NipArr = new int[10];

        private void getchecksum()
        {
            int sum = NipArr[0] * 6 + NipArr[1] * 5 + NipArr[2] * 7 + NipArr[3] * 2 + NipArr[4] * 3 + NipArr[5] * 4 + NipArr[6] * 5 + NipArr[7] * 6 + NipArr[8] * 7;
            int mod11 = sum % 11;
            if (mod11 == 10)
            {
                mod11 = 0;
            }
            NipArr[9] = mod11;
        }

        public string GetNip()
        {
            string nip = "";
            Random rand = new Random();

            for (int i = 0; i <= 8; i++)
            {
                int n = rand.Next(1, 9);
                NipArr[i] = n;
            }

            getchecksum();

            foreach (int i in NipArr)
            {
                nip = nip + i.ToString();
            }
            return nip;
        }
    }
}
